package com.huichenghe.xinlvsh01.slide;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.huichenghe.xinlvsh01.Ble.BluetoothLeService;
import com.huichenghe.xinlvsh01.R;
import com.huichenghe.xinlvsh01.Utils.LocalDataSaveTool;
import com.huichenghe.xinlvsh01.Utils.MyConfingInfo;

public class AboutActivity extends AppCompatActivity
{

    private TextView tvAppVersion, tvHardVersion;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
//        settingTheStatebarAndNavigationbar();
        init();
    }

    private void init()
    {
        tvAppVersion = (TextView)findViewById(R.id.app_version_tv);
        tvAppVersion.setText(getAppVersion());
        tvHardVersion = (TextView)findViewById(R.id.hard_version_tv);
        if(BluetoothLeService.getInstance().isConnectedDevice())
        {
            String v = LocalDataSaveTool.getInstance(AboutActivity.this).readSp(MyConfingInfo.HARD_VERSION);
            tvHardVersion.setText(v);
        }
        else
        {
            tvHardVersion.setText(getString(R.string.not_onn));
        }


        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar_about_activity);
        toolbar.setTitle(getString(R.string.about));    // 设置标题
        toolbar.setTitleTextColor(getResources().getColor(R.color.White_forme));
        setSupportActionBar(toolbar);           // 设置为Actionbar
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);// 显示返回键
        toolbar.setNavigationIcon(R.drawable.back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AboutActivity.this.onBackPressed();
            }
        });
    }


    /**
     * 设置沉浸式状态栏和底部虚拟键全屏
     */
    private void settingTheStatebarAndNavigationbar() {
        // 透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //底部虚拟键透明
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }


    /**
     * 获取app软件版本
     * @return
     */
    private String getAppVersion()
    {
        PackageInfo mPackageInfo;
        try {
            mPackageInfo = AboutActivity.this
                    .getPackageManager()
                    .getPackageInfo(AboutActivity.this.getPackageName(), 0);

            return mPackageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return null;

    }



}
